/*****************************************************************************/
/**
*
* @file ugpiops.h
*
* Header file for u_gpio.c.
*
* <pre>
* MODIFICATION HISTORY:
*
* Ver   Who    Date   	Changes
* ----- ---- ---------- -------------------------------------------------------
* 0.01  abu  12/12/2018 First release
* </pre>
*
******************************************************************************/
#ifndef UGPIOPS_H		/* prevent circular inclusions */
#define UGPIOPS_H		/* by using protection macros */
	
#ifdef __cplusplus
	extern "C" {
#endif

/***************************** Include Files *********************************/
#include "platform.h"
#include "xil_printf.h"
#include "xgpiops.h"

/************************** Constant Definitions *****************************/
typedef enum {
	IntrNull,
	IntrHigh,
	IntrLow,
	IntrRisingEdge,
	IntrFallingEdge,
	IntrAnyEdge
}uGpioPs_IntrType;

/**************************** Type Definitions *******************************/
//================================================================
//basic properties of the pin to be used in the hardware system
typedef struct {
	u8 PinNum;			//MIO/EMIO pin number
	u32 PowerOnState;	//define the power on value when first initialized
}uGpioPs_Output;

//================================================================
//gpiops interrupt handler table
typedef struct
{
	Xil_InterruptHandler Handler;
	void *CallBackRef;
} uGpioPs_IntrTableEntry;

//interrupt properties, including type, priority, handler, target cpu
typedef struct {
	uGpioPs_IntrType IntrType;		//interrupt type
	u8 IntrPriority;				//interrupt priority in GIC register
	u8 CpuId;						//target cpu
	Xil_InterruptHandler Handler;	//interrupt handler
}uGpioPs_Interrupt;

//basic properties of one MIO/EMIO input pin
typedef struct {
	u8 PinNum;				//MIO/EMIO pin number
	u8 IntrEnable;			//enable interrupt or not, 0 for disable, 1 for enable
	uGpioPs_Interrupt Intr;
}uGpioPs_Input;

typedef struct {
	u8 Direction;
	uGpioPs_IntrTableEntry HandlerTable[];
}uGpioPs_Config;

typedef struct {
	uGpioPs_Config *Config;
	u32 IsReady;
}uGpioPs;

//=================================================================
/***************** Macros (Inline Functions) Definitions *********************/
#define xprint xil_printf
#ifndef NDEBUG
	#define DEBUG	xil_printf
#endif

#define uGpioPs_High 1U
#define uGpioPs_Low 0U
#define uGpioPs_Dir_Out 1U
#define uGpioPs_Dir_In 0U
#define uGpioPs_Out_Enable 1U
#define uGpioPs_out_Disable 0U
#define uGpioPs_Int_Enable 1U
#define uGpioPs_Int_Disable 0U

#define InterruptEnable 1U
#define InterruptDisable 0U

#define uGpioPs_ReadPin(PinNum)	XGpioPs_ReadPin(xGpioPs_Ptr,PinNum)

/************************** Variable Definitions *****************************/
	
//========================================================

/************************** Function Prototypes ******************************/
void uGpioPs_Init(XGpioPs *, XGpioPs_Config *);
void uGpioPs_Output_Init(XGpioPs * XGpioPs_Ptr, uGpioPs_Output *uGpioPs_Output_Ptr);
void uGpioPs_SetIntrTypePin(XGpioPs *InstancePtr, uGpioPs_Input *uGpioPs_Input_Ptr);
void uGpioPs_Input_Init(XGpioPs *XGpioPs_Ptr, uGpioPs_Input *uGpioPs_Input_Ptr);
void uPs_EnableIRQ(void);
Xil_InterruptHandler uGpioPsIntrHandler(void *Data);




#ifdef __cplusplus
}
#endif

#endif
